package com.wangjiangwen;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collections;

/**
 * @author tisson
 */
public class CodeGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://106.12.157.87/hyx";
        String username = "root";
        String password = "Mysql1620638653.";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("gavin") // 设置作者
                            .disableOpenDir().dateType(DateType.ONLY_DATE)
                            .outputDir(System.getProperty("user.dir") + "/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.wangjiangwen") // 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") +"/src/main/resources/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("introduce")
                            .controllerBuilder().enableFileOverride().enableRestStyle()
                            .entityBuilder().enableFileOverride().disableSerialVersionUID().enableLombok().idType(IdType.ASSIGN_ID)
                            .serviceBuilder().enableFileOverride().formatServiceFileName("%sService")
                            .mapperBuilder().enableFileOverride().mapperAnnotation(Mapper.class)
                            .build();
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}